var app = getApp()
var c_js = require('../../js/common.js')
Page({
    data: {
        isShowInputLabelArr: [false, false],
        cateInfo: null
    },

    onLoad: function (opt) {
        if (opt.cate){
            var obj = JSON.parse(opt.cate);
            this.setData({
                cateInfo: obj,
                isShowInputLabelArr: [true, true]
            })
        }
        console.log('this.data.cateInfo',this.data.cateInfo)
    },

    submitCateInfo: function (e) {
        var param = e.detail.value
        if (c_js.isEmpty(param.sort)) {
            param.sort = 0
        }
        
        param.uid = app.globalData.shopInfo.userid
        var cate = this.data.cateInfo
        if (cate) {
            param.id = cate.cateId
            param.sql = 'update'
        } else {
            param.sql = 'insert'
        }
        var that = this
        app.getJsonData('api/admin/table_cate_save.php', param, function (res) {
            console.log('table_cate_save:res',res)
            that.reportResult(res)
        })
    },

    reportResult: function (res) {
        if (res.code == 0) {
            app.noticeUpdateTableCateList(res.data)
            wx.navigateBack();
        } else {
            wx.showToast({
                title: res.message,
            })
        }
    },

    showInputLabel: function (e) {
        if (e.detail.value.length > 1) return;
        var index = Number(e.currentTarget.id);
        var isShowArray = this.data.isShowInputLabelArr;
        isShowArray[index] = true;

        this.setData({
            isShowInputLabelArr: isShowArray
        })
        console.log(isShowArray);
        console.log(this.data.isShowInputLabelArr);
        console.log(e.currentTarget.id);
    },


    onShareAppMessage: function () {

    }
})